<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>刷新缓存</title>
    <link rel="stylesheet" href="../../../../component/pear/css/pear.css"/>
    <link rel="stylesheet" href="../../../../admin/css/reset.css"/>
    <style>
        .container {
            position: relative;
        }

        .item {
            margin-top: 200px;
            position: absolute;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="container">
        <div class="item">
            <button class="pear-btn pear-btn-primary pear-btn-sm" lay-on="cache">清除缓存</button>
            <button class="pear-btn pear-btn-primary pear-btn-sm" lay-on="log">清除日志</button>
        </div>
    </div>
</div>
<script src="../../../../component/layui/layui.js"></script>
<script src="../../../../component/pear/pear.js"></script>
<script src="../../../../lms/base64.js"></script>
<script src="../../../../lms/common.js"></script>
<script src="../../../../lms/permission.js"></script>
<script src="../../../../lms/config.js"></script>
<script>

    const REFRESH_CACHE_API = lms_config.api_url + "/adminapi/system/refresh_cache/cache";
    const REFRESH_CACHE_LOG_API = lms_config.api_url + "/adminapi/system/refresh_cache/log";

    //没有登录退回登录页面
    if (!checkLogin()) {
        location.href = lms_config.base_path + "/login.html";
    }

    layui.use(['form', 'jquery', 'notice'], function () {
        let layer = layui.layer;
        let util = layui.util;
        let notice = layui.notice;

        util.on('lay-on', {
            "cache": function () {
                layer.confirm('清除缓存,确定要清除缓存吗？', {icon: 3}, function (index) {
                    layui.$.ajax({
                        url: REFRESH_CACHE_API,
                        type: 'GET',
                        dataType: 'json',
                        success: function (ret) {
                            if (ret && ret.code != -1) {
                                notice.success(ret.msg)
                            } else {
                                notice.error(ret.msg)
                            }
                        },
                        error: function (ret) {
                            alert("出错" + ret.status + "：" + ret.responseText);
                        },
                        complete: function () {
                            layer.close(index);
                        }
                    })
                }, function () {
                    notice.success("取消成功")
                });
            },
            "log": function () {
                layer.confirm('清除日志,确定要清除日志吗？', {icon: 3}, function (index) {
                    layui.$.ajax({
                        url: REFRESH_CACHE_LOG_API,
                        type: 'GET',
                        dataType: 'json',
                        success: function (ret) {
                            if (ret && ret.code != -1) {
                                notice.success(ret.msg)
                            } else {
                                notice.error(ret.msg)
                            }
                        },
                        error: function (ret) {
                            alert("出错" + ret.status + "：" + ret.responseText);
                        },
                        complete: function () {
                            layer.close(index);
                        }
                    })
                }, function () {
                    notice.success("取消成功")
                });
            }
        })
    })


</script>
</body>
</html>
